package substringCount;

import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class SubstringCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个任意的字符串：");
        String input = scanner.nextLine();
        scanner.close();

        for (int i = 1; i <= input.length(); i++) {
            Map<String, Integer> substringCounts = new HashMap<>();

            for (int start = 0; start <= input.length() - i; start++) {
                String substring = input.substring(start, start + i);
                substringCounts.put(substring, substringCounts.getOrDefault(substring, 0) + 1);
            }

            System.out.println("长度为 " + i + " 的子串出现次数：");
            substringCounts.forEach((key, value) -> System.out.println(key + ": " + value));
        }
    }
}
